package com.qujia.markert.controller;

import java.util.List;

import com.qujia.system.service.ISysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.qujia.common.annotation.Log;
import com.qujia.common.core.controller.BaseController;
import com.qujia.common.core.domain.AjaxResult;
import com.qujia.common.enums.BusinessType;
import com.qujia.markert.domain.MarketCoupon;
import com.qujia.markert.service.IMarketCouponService;
import com.qujia.common.utils.poi.ExcelUtil;
import com.qujia.common.core.page.TableDataInfo;

/**
 * 优惠劵管理Controller
 * 
 * @author qujia
 * @date 2020-12-22
 */
@RestController
@RequestMapping("/market/coupon")
public class MarketCouponController extends BaseController
{
    @Autowired
    private IMarketCouponService marketCouponService;
    @Autowired
    private ISysUserService sysUserService;
    /**
     * 查询优惠劵管理列表
     */
    @GetMapping("/list")
    public TableDataInfo list(MarketCoupon marketCoupon)
    {
//        LoginUser currentUser = SecurityUtils.getLoginUser();
//        boolean flag= sysUserService.getUserRole(currentUser);
//        if(!flag){
//            marketCoupon.setStationId(currentUser.getUser().getDeptId());
//        }
        startPage();
        List<MarketCoupon> list = marketCouponService.selectMarketCouponList(marketCoupon);
        return getDataTable(list);
    }

    /**
     * 导出优惠劵管理列表
     */
    @Log(title = "优惠劵管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(MarketCoupon marketCoupon)
    {
        List<MarketCoupon> list = marketCouponService.selectMarketCouponList(marketCoupon);
        ExcelUtil<MarketCoupon> util = new ExcelUtil<MarketCoupon>(MarketCoupon.class);
        return util.exportExcel(list, "coupon");
    }

    /**
     * 获取优惠劵管理详细信息
     */
    @GetMapping(value = "/{couponId}")
    public AjaxResult getInfo(@PathVariable("couponId") Long couponId)
    {
        return AjaxResult.success(marketCouponService.selectMarketCouponById(couponId));
    }

    /**
     * 新增优惠劵管理
     */
    @Log(title = "优惠劵管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MarketCoupon marketCoupon)
    {
        return toAjax(marketCouponService.insertMarketCoupon(marketCoupon));
    }

    /**
     * 修改优惠劵管理
     */
    @Log(title = "优惠劵管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MarketCoupon marketCoupon)
    {
        return toAjax(marketCouponService.updateMarketCoupon(marketCoupon));
    }

    /**
     * 删除优惠劵管理
     */
    @Log(title = "优惠劵管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{couponIds}")
    public AjaxResult remove(@PathVariable Long[] couponIds)
    {
        return toAjax(marketCouponService.deleteMarketCouponByIds(couponIds));
    }
}
